@echo off
REM 项目结构验证脚本
REM 用于验证 Vault MySQL 高并发服务项目的完整性

setlocal enabledelayedexpansion

set RED=[91m
set GREEN=[92m
set YELLOW=[93m
set BLUE=[94m
set NC=[0m

echo %BLUE%=== Vault MySQL 高并发服务 - 项目验证 ===%NC%
echo.

REM 检查核心文件
echo %BLUE%检查核心项目文件...%NC%
set core_files_missing=0

REM Maven 配置文件
if exist "pom.xml" (
    echo %GREEN%✓ pom.xml%NC%
) else (
    echo %RED%✗ pom.xml 缺失%NC%
    set /a core_files_missing+=1
)

REM 应用配置文件
if exist "src\main\resources\application.yml" (
    echo %GREEN%✓ application.yml%NC%
) else (
    echo %RED%✗ application.yml 缺失%NC%
    set /a core_files_missing+=1
)

if exist "src\main\resources\application-docker.yml" (
    echo %GREEN%✓ application-docker.yml%NC%
) else (
    echo %RED%✗ application-docker.yml 缺失%NC%
    set /a core_files_missing+=1
)

REM 主应用类
if exist "src\main\java\com\example\vaultmysql\VaultMysqlApplication.java" (
    echo %GREEN%✓ VaultMysqlApplication.java%NC%
) else (
    echo %RED%✗ VaultMysqlApplication.java 缺失%NC%
    set /a core_files_missing+=1
)

echo.
echo %BLUE%检查服务类...%NC%

REM 服务类
set service_files=(
    "src\main\java\com\example\vaultmysql\service\VaultService.java"
    "src\main\java\com\example\vaultmysql\service\DatabaseConfigService.java"
    "src\main\java\com\example\vaultmysql\service\ConcurrencyTestService.java"
    "src\main\java\com\example\vaultmysql\service\DataInitializationService.java"
)

set service_files_missing=0
for %%f in %service_files% do (
    if exist "%%~f" (
        echo %GREEN%✓ %%~nxf%NC%
    ) else (
        echo %RED%✗ %%~nxf 缺失%NC%
        set /a service_files_missing+=1
    )
)

echo.
echo %BLUE%检查控制器类...%NC%

REM 控制器类
set controller_files=(
    "src\main\java\com\example\vaultmysql\controller\HomeController.java"
    "src\main\java\com\example\vaultmysql\controller\VaultController.java"
    "src\main\java\com\example\vaultmysql\controller\DatabaseController.java"
    "src\main\java\com\example\vaultmysql\controller\TestController.java"
)

set controller_files_missing=0
for %%f in %controller_files% do (
    if exist "%%~f" (
        echo %GREEN%✓ %%~nxf%NC%
    ) else (
        echo %RED%✗ %%~nxf 缺失%NC%
        set /a controller_files_missing+=1
    )
)

echo.
echo %BLUE%检查实体类...%NC%

REM 实体类
set entity_files=(
    "src\main\java\com\example\vaultmysql\entity\DatabaseConfig.java"
    "src\main\java\com\example\vaultmysql\entity\VaultConfig.java"
    "src\main\java\com\example\vaultmysql\entity\TestResult.java"
)

set entity_files_missing=0
for %%f in %entity_files% do (
    if exist "%%~f" (
        echo %GREEN%✓ %%~nxf%NC%
    ) else (
        echo %RED%✗ %%~nxf 缺失%NC%
        set /a entity_files_missing+=1
    )
)

echo.
echo %BLUE%检查仓库类...%NC%

REM 仓库类
set repository_files=(
    "src\main\java\com\example\vaultmysql\repository\DatabaseConfigRepository.java"
    "src\main\java\com\example\vaultmysql\repository\VaultConfigRepository.java"
    "src\main\java\com\example\vaultmysql\repository\TestResultRepository.java"
)

set repository_files_missing=0
for %%f in %repository_files% do (
    if exist "%%~f" (
        echo %GREEN%✓ %%~nxf%NC%
    ) else (
        echo %RED%✗ %%~nxf 缺失%NC%
        set /a repository_files_missing+=1
    )
)

echo.
echo %BLUE%检查前端文件...%NC%

REM 前端文件
set frontend_files=(
    "src\main\resources\templates\index.html"
    "src\main\resources\templates\about.html"
    "src\main\resources\static\css\style.css"
    "src\main\resources\static\js\app.js"
)

set frontend_files_missing=0
for %%f in %frontend_files% do (
    if exist "%%~f" (
        echo %GREEN%✓ %%~nxf%NC%
    ) else (
        echo %RED%✗ %%~nxf 缺失%NC%
        set /a frontend_files_missing+=1
    )
)

echo.
echo %BLUE%检查Docker配置文件...%NC%

REM Docker 文件
set docker_files=(
    "Dockerfile"
    "docker-compose.yml"
    ".dockerignore"
)

set docker_files_missing=0
for %%f in %docker_files% do (
    if exist "%%~f" (
        echo %GREEN%✓ %%~f%NC%
    ) else (
        echo %RED%✗ %%~f 缺失%NC%
        set /a docker_files_missing+=1
    )
)

echo.
echo %BLUE%检查部署脚本...%NC%

REM 部署脚本
if exist "deploy.sh" (
    echo %GREEN%✓ deploy.sh (Linux/macOS)%NC%
) else (
    echo %YELLOW%! deploy.sh 缺失 (Linux/macOS)%NC%
)

if exist "deploy.bat" (
    echo %GREEN%✓ deploy.bat (Windows)%NC%
) else (
    echo %RED%✗ deploy.bat 缺失 (Windows)%NC%
)

echo.
echo %BLUE%检查文档文件...%NC%

REM 文档文件
set doc_files=(
    "README.md"
    "QUICKSTART.md"
    "API.md"
)

set doc_files_missing=0
for %%f in %doc_files% do (
    if exist "%%~f" (
        echo %GREEN%✓ %%~f%NC%
    ) else (
        echo %RED%✗ %%~f 缺失%NC%
        set /a doc_files_missing+=1
    )
)

echo.
echo %BLUE%检查目录结构...%NC%

REM 检查目录结构
set directories=(
    "src\main\java\com\example\vaultmysql"
    "src\main\java\com\example\vaultmysql\controller"
    "src\main\java\com\example\vaultmysql\service"
    "src\main\java\com\example\vaultmysql\entity"
    "src\main\java\com\example\vaultmysql\repository"
    "src\main\java\com\example\vaultmysql\config"
    "src\main\resources"
    "src\main\resources\templates"
    "src\main\resources\static"
    "src\main\resources\static\css"
    "src\main\resources\static\js"
)

set directories_missing=0
for %%d in %directories% do (
    if exist "%%~d" (
        echo %GREEN%✓ %%~d\%NC%
    ) else (
        echo %RED%✗ %%~d\ 缺失%NC%
        set /a directories_missing+=1
    )
)

echo.
echo %BLUE%=== 验证结果汇总 ===%NC%
echo.

set /a total_missing=!core_files_missing!+!service_files_missing!+!controller_files_missing!+!entity_files_missing!+!repository_files_missing!+!frontend_files_missing!+!docker_files_missing!+!doc_files_missing!+!directories_missing!

if !total_missing! equ 0 (
    echo %GREEN%🎉 项目验证通过！所有必要文件都已存在。%NC%
    echo %GREEN%✓ 核心文件: 完整%NC%
    echo %GREEN%✓ 服务类: 完整%NC%
    echo %GREEN%✓ 控制器: 完整%NC%
    echo %GREEN%✓ 实体类: 完整%NC%
    echo %GREEN%✓ 仓库类: 完整%NC%
    echo %GREEN%✓ 前端文件: 完整%NC%
    echo %GREEN%✓ Docker配置: 完整%NC%
    echo %GREEN%✓ 文档文件: 完整%NC%
    echo %GREEN%✓ 目录结构: 完整%NC%
    echo.
    echo %BLUE%项目已准备就绪，可以进行部署！%NC%
    echo.
    echo %YELLOW%下一步操作建议：%NC%
    echo 1. 安装 Docker Desktop
    echo 2. 运行 deploy.bat init 初始化项目
    echo 3. 运行 deploy.bat build 构建应用
    echo 4. 运行 deploy.bat start 启动服务
) else (
    echo %RED%❌ 项目验证失败！发现 !total_missing! 个缺失项。%NC%
    echo.
    echo %YELLOW%缺失统计：%NC%
    if !core_files_missing! gtr 0 echo %RED%- 核心文件: !core_files_missing! 个缺失%NC%
    if !service_files_missing! gtr 0 echo %RED%- 服务类: !service_files_missing! 个缺失%NC%
    if !controller_files_missing! gtr 0 echo %RED%- 控制器: !controller_files_missing! 个缺失%NC%
    if !entity_files_missing! gtr 0 echo %RED%- 实体类: !entity_files_missing! 个缺失%NC%
    if !repository_files_missing! gtr 0 echo %RED%- 仓库类: !repository_files_missing! 个缺失%NC%
    if !frontend_files_missing! gtr 0 echo %RED%- 前端文件: !frontend_files_missing! 个缺失%NC%
    if !docker_files_missing! gtr 0 echo %RED%- Docker配置: !docker_files_missing! 个缺失%NC%
    if !doc_files_missing! gtr 0 echo %RED%- 文档文件: !doc_files_missing! 个缺失%NC%
    if !directories_missing! gtr 0 echo %RED%- 目录结构: !directories_missing! 个缺失%NC%
    echo.
    echo %YELLOW%请检查并补充缺失的文件后重新验证。%NC%
)

echo.
echo %BLUE%验证完成时间: %date% %time%%NC%
echo.
pause
endlocal